import { useMemo, useState } from "react"

function fib(n) {
    console.log("计算函数执行了")
    if (n < 3) return 1
    return fib(n - 2) + fib(n - 1)
}

const Menu = () => {
    const [count1, setCount1] = useState(0)

    const result = useMemo(() => {
        return fib(count1)
    }, [count1])

    // const result = fib(count1)

    const [count2, setCount2] = useState(0)
    console.log("组件重新渲染")

    return (
        <div>
            <div>useMemo</div>
            <div onClick={() => setCount1(count1 + 1)}>change count1:{count1}</div>
            <div onClick={() => setCount2(count2 + 1)}>change count2:{count2}</div>
            <div>{result}</div>
        </div>
    )
}

export default Menu